<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['set']=$this->plugin_setting('basic');
$keywords=$this->plugin_setting('search');
$return['params']=array('jy'=>1);
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['order']=$_RQ['order'];
	$groupparams=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($parentid){
		$return['pid']=0;
	}
	$category=pdo_getall('jy_aikefu_group',$groupparams,array(),'id','paixu desc');
	//推荐分类
	$groupparams['isrecommand']=1;
	$recommend=pdo_getall('jy_aikefu_group',$groupparams);
	$return['recommend']=$return['childs']=$recommend;
	$return['category']=$category;
	$title=$return['setting']['share_title']?'全部客服'.$return['setting']['share_title']:'全部客服-在线商城';
	$desc=$return['setting']['share_desc']?'客服列表-'.$return['setting']['share_desc']:'在线商城，一个属于自己的个人商城！';
	if($_RQ['pcate'] || $_RQ['pid']){
		$pcate=$_RQ['pcate']?intval($_RQ['pcate']):intval($_RQ['pid']);
		$return['params']['pcate']=$pcate;
		$pcateinfo=pdo_get('jy_aikefu_group',array('id'=>$pcate));
		$title=$pcateinfo['title'];
		$desc=$pcateinfo['desc'];
	}
	if($_RQ['ccate'] || $_RQ['cid']){
		$ccate=$_RQ['ccate']?intval($_RQ['ccate']):intval($_RQ['cid']);
		$return['params']['ccate']=$ccate;
		$pcateinfo=pdo_get('jy_aikefu_group',array('id'=>$pcate));
		$title=$pcateinfo['title'];
		$desc=$pcateinfo['desc'];
	}elseif($_RQ['order']=='isrecommand'){
		$title='推荐客服';
	}elseif($_RQ['order']=='isnew'){
		$title='新客服';
	}elseif($_RQ['order']=='ishot'){
		$title='热询客服';
	}
	$return['shopset']=plugin('jy_weishop')->plugin_setting('shopset');
	$return['sharedata']=array(
		'title'=>$title,
		'desc'=>$desc,
		'link'=>custom_url('jy_aikefu/goods.index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['setting']['share_image']
	);
	$keywords='客服列表,'.$return['setting']['share_keywords']?:$return['sharedata']['desc'];
	$keywords=$pcateinfo['keywords']?:$keywords;
	$return['params']['keyword']=$_RQ['keyword']?:'';
	set_html('title','客服列表');
	set_html('description',$desc);
	set_html('keywords',$keywords);
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$table='jy_aikefu_worker';
	if($_RQ['pid']){
		if($_RQ['pid']=='merch'){
			$table='jy_merch_user';
			if($_RQ['keyword']){
				$params['merchname like']='%'.trim($_RQ['keyword']).'%';
			}
		}else{
			$params['groupid']=$_RQ['pid'];
			$params['merchid']=0;
			if($_RQ['keyword']){
				$params['title like']='%'.trim($_RQ['keyword']).'%';
			}
		}
	}else{
		if($_RQ['keyword']){
			$params['title like']='%'.trim($_RQ['keyword']).'%';
		}
	}
	if($_RQ['pcate']){
		$params['groupid']=$_RQ['pcate'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice($table,$params,array($pindex,$psize),$total,$fields,'','id desc');
	if(empty($list)){
		exi('none');
	}else{
		foreach($list as $k=>&$itemv){
			if($_RQ['pid']=='merch'){
				$itemv['merchid']=$itemv['id'];
				$itemv['title']=$itemv['merchname'].'[客服]';
				$itemv['worker']=pdo_get('jy_aikefu_worker',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$itemv['id']));
				$itemv['star']=$itemv['worker']['star'];
				$itemv['salenum']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$itemv['worker']['id']));
				$itemv['api_data']=json_decode($itemv['worker']['api_data'],true);
				$itemv['grouptitle']=pdo_getcolumn('jy_aikefu_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$itemv['worker']['groupid']),'title');
			}else{
				$itemv['merchid']=0;
				$itemv['salenum']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$itemv['id']));
				$itemv['api_data']=json_decode($itemv['api_data'],true);
				$itemv['grouptitle']=pdo_getcolumn('jy_aikefu_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$itemv['groupid']),'title');
			}
		}
		exi($list);
	}
}	
?>